function promiseRequest(obj) {
    return new Promise(function (resolve, reject) {
        if (obj.url === undefined) throw new Error('请求路径不能为空！')
        if (typeof obj.url != 'string') throw new Error('请求路径错误！')
        if (obj.dataType === undefined) obj.dataType = 'json'
        if (obj.method === undefined) obj.method = 'get'
        if (obj.method.toLowerCase() != 'get' && obj.method.toLowerCase() != 'post' && obj.method.toLowerCase() != 'put' && obj.method.toLowerCase() != 'delete') throw new Error('请求方式不正确！')
        if (obj.async === undefined) obj.async = true
        if (typeof obj.async != 'boolean') throw new Error('同步false异步true！')
        if (obj.success === undefined) obj.success = () => { }
        if (typeof obj.success != 'function') throw new Error('success是函数！ ')
        if (obj.error === undefined) obj.error = () => { }
        if (typeof obj.error != 'function') throw new Error('error是函数！')
        let data
        if (obj.data != undefined) {
            if (Object.prototype.toString.call(obj.data) === '[object Object]') {
                let arr = []
                for (let key in obj.data) {
                    arr.push(key + '=' + obj.data[key])
                }
                data = arr.join('&')
            } else if (Object.prototype.toString.call(obj.data) === '[object String]') data = obj.data
            else throw new Error('data是字符串或对象！')
            if (obj.method.toLowerCase() === 'get') obj.url += '?' + data
        }
        var xhr = new XMLHttpRequest;
        xhr.open(obj.method, obj.url, obj.async);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    switch (obj.dataType) {
                        case 'json':
                            var res = xhr.responseText;
                            res = JSON.parse(res)
                            break;
                        case 'xml':
                            var res = xhr.responseXML
                            break;
                        case 'text':
                            var res = xhr.responseText;
                            break;
                        default:
                            throw new Error('dataType必须是json或text或xml')
                    }
                    resolve(res)
                } else reject('错误')
            }
        }
        for (let key in obj.headers) xhr.setRequestHeader(key, obj.headers[key])
        if (obj.method.toLowerCase() === 'post' && data) {
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            xhr.send(data)
            return
        }
        xhr.send()
    })

}